package csvloader.tables;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import com.db.BeanBase;
import com.db.Table;

import csvloader.beans.M_WebsiteBean;

public class M_WebsiteTable extends Table{
	
	public static final String TABLE_NAME = "M_WEBSITE";
	public static final String COL_WEBSITE_CODE = "WEBSITE_CODE";
	public static final String COL_WEBSITE_NAME = "WEBSITE_NAME";
	public static final String COL_URL = "URL";
	public static final String COL_DELETE_FLAG = "DELETE_FLAG";
	
	
	public BeanBase[] selectAll(Connection conn) throws SQLException{
		final String sql = "SELECT " 
			+ COL_WEBSITE_CODE + ","
			+ COL_WEBSITE_NAME + ","
			+ COL_URL + ","
			+ COL_DELETE_FLAG 
			+ " FROM " + TABLE_NAME
			;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		Vector<M_WebsiteBean> v = new Vector<M_WebsiteBean> ();
        try{
    		stmt = conn.prepareStatement(sql);
    		rs = stmt.executeQuery();
    		int i = 1;
            while( rs.next() ) {
            	i = 1;
            	M_WebsiteBean rec = new M_WebsiteBean();
            	rec.setWebsiteCode(rs.getInt(i++));
            	rec.setWebsiteName(rs.getString(i++));
            	rec.setUrl(rs.getString(i++));
            	rec.setDeleteFlag(rs.getInt(i++)== NOT_DELETE_FLAG);
            	v.add(rec);
            }
        } finally {
            if(rs != null){
                rs.close();
            }
            
            if (stmt != null){
            	stmt.close();
            }
        }
        return (M_WebsiteBean[])v.toArray(new M_WebsiteBean[v.size()]);
	}
	
}
